using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Aces4All.Logger
{
    /// <summary>
    /// Entry to be made to a log
    /// </summary>
    public class LogEntry
    {
        #region LogEntry constants

        private const string LOCALHOST = ".";
        private const string EMPTY = "";

        #endregion

        #region LogEntry public constructors

        /// <summary>
        /// Creates new LogEntry instance
        /// </summary>
        public LogEntry()
        {
            this.m_TimeStamp = Aces4All.Date.TimeStamp.GetTimestamp();
            this.m_EntryType = EventLogEntryType.Information;
            this.m_Computername = LOCALHOST;
            this.m_Source = EMPTY;
            this.m_Message = EMPTY;
        }

        /// <summary>
        /// Creates new LogEntryInstance
        /// </summary>
        /// <param name="entryType">
        /// Type or classification of log entry
        /// </param>
        /// <param name="computerName">
        /// Name of computer submitting the log entry
        /// </param>
        /// <param name="applicationSource">
        /// Source of the application submitting the log entry
        /// </param>
        /// <param name="message">
        /// Log entry's message
        /// </param>
        public LogEntry(EventLogEntryType entryType, string computerName, 
            string applicationSource, string message)
        {
            this.m_TimeStamp = Aces4All.Date.TimeStamp.GetTimestamp();
            this.m_EntryType = entryType;
            this.m_Computername = computerName;
            this.m_Source = applicationSource;
            this.m_Message = message;
        }

        #endregion

        #region LogEntry public properties

        private string m_TimeStamp;
        /// <summary>
        /// Gets time stamp
        /// </summary>
        public string TimeStamp
        {
            get
            {
                return this.m_TimeStamp;
            }
        }

        private EventLogEntryType m_EntryType;
        /// <summary>
        /// Gets or sets log entry type
        /// </summary>
        public EventLogEntryType EntryType
        {
            get
            {
                return this.m_EntryType;
            }
            set
            {
                this.m_EntryType = value;
            }
        }

        private string m_Computername;
        /// <summary>
        /// Get's or sets name of computer sending log entry
        /// </summary>
        public string ComputerName
        {
            get
            {
                return this.m_Computername;
            }
            set
            {
                this.m_Computername = value;
            }
        }

        private string m_Source;
        /// <summary>
        /// Gets or sets name of application sending log entry
        /// </summary>
        public string Soure
        {
            get
            {
                return this.m_Source;
            }
            set
            {
                this.m_Source = value;
            }
        }

        private string m_Message;
        /// <summary>
        /// Gets or sets messade of log entry
        /// </summary>
        public string Message
        {
            get
            {
                return this.m_Message;
            }
            set
            {
                this.m_Message = value;
            }
        }

        #endregion

        #region LogEntry public methods

        /// <summary>
        /// Gets log entry as a string array
        /// </summary>
        /// <returns>Values of log entry as string array</returns>
        public string[] GetValues()
        {
            string[] values = new string[] {
                this.m_TimeStamp, 
                Enum.GetName(typeof(EventLogEntryType), 
                this.m_EntryType), this.m_Computername, 
                this.m_Source, this.m_Message};

            return values;
        }

        #endregion
    }
}
